package com.eamois.dao.manual.impl;

import java.sql.SQLException;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.eamois.dao.impl.BaseDaoImpl;
import com.eamois.dao.manual.TechnologyTypeDao;
import com.eamois.domain.manual.Ensip;
import com.eamois.domain.manual.Manual;
import com.eamois.domain.manual.TechnologyType;

public class TechnologyTypeDaoImpl extends BaseDaoImpl<TechnologyType> implements TechnologyTypeDao{

	@SuppressWarnings("unchecked")
	public Collection<TechnologyType> findAllType() {
		// TODO Auto-generated method stub
		return (Collection<TechnologyType>)this.getHibernateTemplate().execute(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = session.createCriteria(TechnologyType.class);
				return criteria.list();
			}
		});
	}

	@SuppressWarnings("unchecked")
	public Collection<TechnologyType> findTypeByOther(final Manual manual, final Ensip ensip) {
		// TODO Auto-generated method stub
		return (Collection<TechnologyType>)this.getHibernateTemplate().execute(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = session.createCriteria(TechnologyType.class);
				criteria.add(Restrictions.eq("manual", manual));
				criteria.add(Restrictions.eq("ensip", ensip));
				return criteria.list();
			}
		});
	}

}
